package com.action.ui.view;

import android.content.Context;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by jiansheng.li on 2018/4/11.
 */

public class ClearListenEditText extends android.support.v7.widget.AppCompatEditText implements View.OnFocusChangeListener {

	public ClearListenEditText(Context context) {
		super(context);
		setOnFocusChangeListener(this);
	}

	public ClearListenEditText(Context context, AttributeSet attrs) {
		super(context, attrs);
		setOnFocusChangeListener(this);
	}

	public ClearListenEditText(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
	}
	private TextWatcher textWatcher=null;

	public void setTextWatcher(TextWatcher textWatcher) {
		this.textWatcher = textWatcher;
	}

	@Override
	public void onFocusChange(View view, boolean b) {
		if(b){//有焦点
			addTextChangedListener(textWatcher);
		}else {
			removeTextChangedListener(textWatcher);
		}
	}
}
